// 防盗链
// 导入express
const express = require('express');
const path = require('path')


// 创建应用
const app = express();

const checkReferer = (req, res, next) => {
    const referer = req.get('referer')
    console.log(referer);
    if (referer) {
        const url = new URL(referer)
        const hostname = url.hostname;

        if (hostname === '127.0.0.1') {
            next()
        } else {
            res.status(404).send('404 not found')
        }
    }
}

app.use(checkReferer)
app.use(express.static(path.resolve(__dirname, './assets')))


// 监听端口，启用服务
app.listen(3000, () => {
    console.log('服务已启动，port 3000 正在监听...');
})

